package routers

import (
	"go-mp-starter/app/controllers/apiv1"
	"go-mp-starter/app/controllers/common"
	"go-mp-starter/app/middleware"
	"go-mp-starter/app/services"
	"net/http"

	"github.com/gin-gonic/gin"
)

func SetApiGroupRoutes(router *gin.RouterGroup) {
	router.GET("/ping", func(ctx *gin.Context) {
		ctx.String(http.StatusOK, "pong")
	})

	// 测试路由
	router.GET("/test", func(ctx *gin.Context) {
		ctx.JSON(http.StatusOK, gin.H{
			"code": 200,
			"msg":  "success",
			"data": map[string]interface{}{
				"path": "/test",
			},
		})
	})

	// 用户注册
	router.POST("/auth/register", apiv1.Register)
	// 用户登陆
	router.POST("/auth/login", apiv1.Login)

	// 使用中间件
	apiRouter := router.Group("").Use(middleware.JWTAuth(services.AppGuardName))
	{
		// 用户信息
		apiRouter.POST("/auth/info", apiv1.Info)
		// 用户登出
		apiRouter.POST("/auth/logout", apiv1.Logout)
		// 图片上传
		apiRouter.POST("/image_upload", common.ImageUpload)
	}

	// 在可刷新时间内的的Jwt
	routerWithToken := router.Group("").Use(middleware.JWTAuthUnverify(services.AppGuardName))
	{
		// renew jwt token
		routerWithToken.POST("/auth/refresh", apiv1.Refresh)
	}
}
